/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.slice.imageview.pictureselector;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.agp.components.TableLayoutManager;

import com.xuexiang.xuidemo.ResourceTable;

import java.util.ArrayList;
import java.util.List;

/**
 * 图库选择
 *
 * @since 2021-04-13
 */
public class PictureSelectorSlice extends AbilitySlice implements Component.ClickedListener, ImageSelectGridAdapter.OnAddPicClickListener {
    private ImageSelectGridAdapter mAdapter;
    private List<LocalMedia> mSelectList = new ArrayList<>();

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_picture_selectore_layout);
        initComponent();
    }

    private void initComponent() {
        setComponentClick(ResourceTable.Id_image_back);
        setComponentClick(ResourceTable.Id_text_select);
        setComponentClick(ResourceTable.Id_button_no_camera);
        setComponentClick(ResourceTable.Id_button_one_photo);
        setComponentClick(ResourceTable.Id_button_photo_gif);
        ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list_container);
        TableLayoutManager tableLayoutManager = new TableLayoutManager();
        tableLayoutManager.setColumnCount(4);
        listContainer.setLayoutManager(tableLayoutManager);
        mAdapter = new ImageSelectGridAdapter(this, this);
        mAdapter.setSelectList(mSelectList);
        mAdapter.setSelectMax(8);
        listContainer.setItemProvider(mAdapter);

        mAdapter.setOnItemClickListener((position, v) -> {

        });
    }

    private void setComponentClick(int id) {
        findComponentById(id).setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                onBackPressed();
                break;
            case ResourceTable.Id_text_select:

                break;
            case ResourceTable.Id_button_no_camera:

                break;
            case ResourceTable.Id_button_one_photo:

                break;
            case ResourceTable.Id_button_photo_gif:

                break;
        }
    }

    @Override
    public void onAddPicClick() {

    }
}
